

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/bear.jpg">
  <link rel="icon" href="/img/bear.jpg">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Wahoyu">
  <meta name="keywords" content="">
  
    <meta name="description" content="一套数据库练习流程帮你练习常用SQL语句">
<meta property="og:type" content="article">
<meta property="og:title" content="SQL语句练习">
<meta property="og:url" content="http://example.com/2022/06/05/SQL%E5%9F%BA%E7%A1%80%E8%AF%AD%E5%8F%A5%E6%97%A5%E5%B8%B8%E7%BB%83%E4%B9%A0/index.html">
<meta property="og:site_name" content="哆啦是个梦-A Coding Bear">
<meta property="og:description" content="一套数据库练习流程帮你练习常用SQL语句">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://example.com/image/sql.jpg">
<meta property="article:published_time" content="2022-06-05T02:07:00.000Z">
<meta property="article:modified_time" content="2022-08-28T11:19:39.711Z">
<meta property="article:author" content="Wahoyu">
<meta property="article:tag" content="数据库">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="http://example.com/image/sql.jpg">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>SQL语句练习 - 哆啦是个梦-A Coding Bear</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  



  
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/bynotes/texiao/source/css/shubiao.css#.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.0","typing":{"enable":true,"typeSpeed":90,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":3},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>

  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 30vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>哆啦是个梦</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="SQL语句练习"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        Wahoyu
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-06-05 10:07" pubdate>
          2022年6月5日 上午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          9.5k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          79 分钟
        
      </span>
    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar category-bar" style="margin-right: -1rem">
    





<div class="category-list">
  
  
    
    
    
    <div class="category row nomargin-x">
      <a class="category-item 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="开发"
        id="heading-3ff3c3e26a68112c11c3e80f2a26896e" role="tab" data-toggle="collapse" href="#collapse-3ff3c3e26a68112c11c3e80f2a26896e"
        aria-expanded="true"
      >
        开发
        <span class="list-group-count">(9)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-3ff3c3e26a68112c11c3e80f2a26896e"
           role="tabpanel" aria-labelledby="heading-3ff3c3e26a68112c11c3e80f2a26896e">
        
        
          
  <div class="category-post-list">
    
    
      
      
        <a href="/2022/06/05/SQL%E5%9F%BA%E7%A1%80%E8%AF%AD%E5%8F%A5%E6%97%A5%E5%B8%B8%E7%BB%83%E4%B9%A0/" title="SQL语句练习"
           class="list-group-item list-group-item-action
           active">
          <span class="category-post">SQL语句练习</span>
        </a>
      
    
      
      
        <a href="/2022/06/19/%E5%85%B3%E4%BA%8E%E5%8F%8D%E5%B0%84%E4%B8%8E%E6%B3%A8%E8%A7%A3%E7%9A%84%E7%90%86%E8%A7%A3%E4%B8%8E%E6%80%BB%E7%BB%93/" title="关于反射与注解的理解与总结"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">关于反射与注解的理解与总结</span>
        </a>
      
    
      
      
        <a href="/2022/07/06/JavaWeb/" title="基于Java Web的图书管理系统"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">基于Java Web的图书管理系统</span>
        </a>
      
    
      
      
        <a href="/2022/06/27/%E5%9F%BA%E4%BA%8EMybatis-JUL-Lombok-Maven%E7%9A%84%E5%9B%BE%E4%B9%A6%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F%EF%BC%88%E5%B8%A6%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%EF%BC%89/" title="基于Mybatis的图书管理系统"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">基于Mybatis的图书管理系统</span>
        </a>
      
    
      
      
        <a href="/2022/07/26/BookManagerSSM/" title="基于SSM+Security的图书管理系统"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">基于SSM+Security的图书管理系统</span>
        </a>
      
    
      
      
        <a href="/2022/06/10/%E7%AE%80%E5%8D%95%E7%AE%97%E6%B3%95%EF%BC%88Java%E5%AE%9E%E7%8E%B0%EF%BC%89/" title="排序与搜索算法（Java实现）"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">排序与搜索算法（Java实现）</span>
        </a>
      
    
      
      
        <a href="/2022/06/08/Java%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E7%AE%80%E5%8D%95%E5%AE%9E%E7%8E%B0/" title="数据结构实现（Java）"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">数据结构实现（Java）</span>
        </a>
      
    
      
      
        <a href="/2022/08/30/%E6%97%A5%E5%BF%97%E8%BF%9B%E5%8C%96%EF%BC%9AAOP+%E8%87%AA%E5%AE%9A%E4%B9%89%E6%B3%A8%E8%A7%A3%E5%AE%9E%E7%8E%B0%E6%97%A5%E5%BF%97%E8%BE%93%E5%87%BA/" title="日志进化：AOP+自定义注解实现日志输出"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">日志进化：AOP+自定义注解实现日志输出</span>
        </a>
      
    
      
      
        <a href="/2022/06/03/%E8%A7%A3%E5%86%B3Linux%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E6%AF%8F%E6%AC%A1%E8%A6%81source-etc-profile%E9%97%AE%E9%A2%98/" title="解决Linux环境变量每次要source /etc/profile问题"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">解决Linux环境变量每次要source /etc/profile问题</span>
        </a>
      
    
  </div>

        
      </div>
    </div>
  
</div>


  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">SQL语句练习</h1>
            
            <div class="markdown-body">
              
              <p>一套数据库练习流程帮你练习常用SQL语句</p>
<span id="more"></span>


<h2 id="1、DDL-创建数据库，创建表"><a href="#1、DDL-创建数据库，创建表" class="headerlink" title="1、DDL(创建数据库，创建表)"></a>1、DDL(创建数据库，创建表)</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><code class="hljs SQL">删除数据库<br>创建数据库<br>使用数据库<br><br>创建表<span class="hljs-number">1</span>student:<br>  学号，<span class="hljs-type">varchar</span>（<span class="hljs-number">20</span>），主键不空，备注学号主码<br>  姓名，<span class="hljs-type">varchar</span>（<span class="hljs-number">20</span>），不空，备注学生姓名<br>  性别，<span class="hljs-type">varchar</span>（<span class="hljs-number">20</span>），不空，备注学生性别<br>  生日，时间，备注学生出生年月<br>  班级，<span class="hljs-type">varchar</span>（<span class="hljs-number">20</span>），备注学生所在班级<br>创建表<span class="hljs-number">2</span>course:<br>  课程号，<span class="hljs-type">varchar</span>（<span class="hljs-number">20</span>），主键，非空，备注课程号（主码）<br>  课程名，<span class="hljs-type">varchar</span>（<span class="hljs-number">20</span>），非空，备注课程名称<br>  教师名，<span class="hljs-type">varchar</span>（<span class="hljs-number">20</span>），非空，备注教工编号<br>创建表<span class="hljs-number">3</span>score：<br>  序号，<span class="hljs-type">int</span>,主键，自增，备注主键自增<br>  学号，<span class="hljs-type">varchar</span>(<span class="hljs-number">20</span>)，非空，备注学号<br>  课程号，<span class="hljs-type">varchar</span>(<span class="hljs-number">20</span>)，非空，备注课程号<br>  成绩，从<span class="hljs-number">1</span>到<span class="hljs-number">4</span>，备注成绩<br>创建表<span class="hljs-number">4</span>teacher:<br>  教师号，<span class="hljs-type">varchar</span>(<span class="hljs-number">20</span>),主键非空，备注教工编号（主码）<br>  教师名字，<span class="hljs-type">varchar</span>(<span class="hljs-number">20</span>)，非空，备注教工姓名<br>  性别，<span class="hljs-type">varchar</span>(<span class="hljs-number">20</span>)，非空，备注教工性别<br>  生日，时间，备注教工出生年月<br>  职称（prof）,<span class="hljs-type">varchar</span>(<span class="hljs-number">20</span>),备注职称<br>  部门，<span class="hljs-type">varchar</span>(<span class="hljs-number">20</span>)，非空，备注教工所在部门<br>  <br><br></code></pre></td></tr></table></figure>

<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><code class="hljs SQL"><span class="hljs-keyword">DROP</span> DATABASE IF <span class="hljs-keyword">EXISTS</span> `test`;<br><br><span class="hljs-keyword">CREATE</span> DATABASE `test`;<br><br>USE `test`<br><br><br><span class="hljs-comment">-- 表一：student学生use)</span><br><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> student(<br>    sno <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">PRIMARY</span> KEY <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> COMMENT<span class="hljs-string">&#x27;学号(主码)&#x27;</span>,<br>    sname <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> COMMENT<span class="hljs-string">&#x27;学生姓名&#x27;</span>,<br>    ssex <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> COMMENT<span class="hljs-string">&#x27;学生性别&#x27;</span>,<br>    sbirthday DATETIME COMMENT<span class="hljs-string">&#x27;学生出生年月&#x27;</span>,<br>    class <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">20</span>) COMMENT<span class="hljs-string">&#x27;学生所在班级&#x27;</span><br>);<br><span class="hljs-comment">-- 表（二）Course（课程表）</span><br><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> course(<br>    cno <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">PRIMARY</span> KEY <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> COMMENT<span class="hljs-string">&#x27;课程号(主码)&#x27;</span>,<br>    cname <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> COMMENT<span class="hljs-string">&#x27;课程名称&#x27;</span>,<br>    tno <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> COMMENT<span class="hljs-string">&#x27;教工编号&#x27;</span><br>);<br><span class="hljs-comment">-- 表（三）Score(成绩表)</span><br><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> score(<br>    id <span class="hljs-type">INT</span> <span class="hljs-keyword">PRIMARY</span> KEY AUTO_INCREMENT COMMENT<span class="hljs-string">&#x27;主键自增&#x27;</span>,<br>    sno <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> COMMENT<span class="hljs-string">&#x27;学号&#x27;</span>,<br>    cno <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> COMMENT<span class="hljs-string">&#x27;课程号&#x27;</span>,<br>    degree <span class="hljs-type">DECIMAL</span>(<span class="hljs-number">4</span>,<span class="hljs-number">1</span>) COMMENT<span class="hljs-string">&#x27;成绩&#x27;</span><br>);<br><span class="hljs-comment">-- 表四 teacher(教师表)</span><br><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> teacher(<br>    tno <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">PRIMARY</span> KEY <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> COMMENT<span class="hljs-string">&#x27;教工编号(主码)&#x27;</span>,<br>    tname <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> COMMENT<span class="hljs-string">&#x27;教工姓名&#x27;</span>,<br>    tsex <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> COMMENT<span class="hljs-string">&#x27;教工性别&#x27;</span>,<br>    tbirthday DATETIME COMMENT<span class="hljs-string">&#x27;教工出生年月&#x27;</span>,<br>    prof <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">20</span>) COMMENT<span class="hljs-string">&#x27;职称&#x27;</span>,<br>    depart <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> COMMENT<span class="hljs-string">&#x27;教工所在部门&#x27;</span><br>);<br></code></pre></td></tr></table></figure>

<p>额外练习对表的修改和删除语句</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs SQL"><span class="hljs-comment">-- 创建表5以及字段</span><br>  <span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> `test`.`table5`(<br>   `id` <span class="hljs-type">INT</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">PRIMARY</span> KEY <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> AUTO_INCREMENT COMMENT <span class="hljs-string">&#x27;待修改&#x27;</span><br>   `id2` <span class="hljs-type">INT</span>(<span class="hljs-number">20</span>) COMMENT <span class="hljs-string">&#x27;待删除&#x27;</span><br>   );<br><span class="hljs-comment">-- 修改表名</span><br>RENAME <span class="hljs-keyword">TABLE</span> `test`.`table5` <span class="hljs-keyword">TO</span> `test`.`deleting`;<br><span class="hljs-comment">-- 修改字段</span><br><span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> `test`.`deleting` CHANGE `id` `id` <span class="hljs-type">INT</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> AUTO_INCREMENT COMMENT <span class="hljs-string">&#x27;待删除&#x27;</span>;<br><span class="hljs-comment">-- 删除字段id2</span><br><span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> `test`.`deleting` <span class="hljs-keyword">DROP</span> <span class="hljs-keyword">COLUMN</span> `id2`;<br></code></pre></td></tr></table></figure>

<h2 id="2、DML（针对数据的控制语言）"><a href="#2、DML（针对数据的控制语言）" class="headerlink" title="2、DML（针对数据的控制语言）"></a>2、DML（针对数据的控制语言）</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><code class="hljs SQL"><span class="hljs-comment">-- 学生表数据的插入：</span><br><span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> student <span class="hljs-keyword">VALUES</span><br>(<span class="hljs-string">&#x27;108&#x27;</span>,<span class="hljs-string">&#x27;曾华&#x27;</span>,<span class="hljs-string">&#x27;男&#x27;</span>,<span class="hljs-string">&#x27;1977-09-01&#x27;</span>,<span class="hljs-string">&#x27;95033&#x27;</span>),<br>(<span class="hljs-string">&#x27;105&#x27;</span>,<span class="hljs-string">&#x27;匡明&#x27;</span>,<span class="hljs-string">&#x27;男&#x27;</span>,<span class="hljs-string">&#x27;1977-09-01&#x27;</span>,<span class="hljs-string">&#x27;95031&#x27;</span>),<br>(<span class="hljs-string">&#x27;107&#x27;</span>,<span class="hljs-string">&#x27;王丽&#x27;</span>,<span class="hljs-string">&#x27;女&#x27;</span>,<span class="hljs-string">&#x27;1977-09-01&#x27;</span>,<span class="hljs-string">&#x27;95033&#x27;</span>),<br>(<span class="hljs-string">&#x27;101&#x27;</span>,<span class="hljs-string">&#x27;李军&#x27;</span>,<span class="hljs-string">&#x27;男&#x27;</span>,<span class="hljs-string">&#x27;1977-09-01&#x27;</span>,<span class="hljs-string">&#x27;95033&#x27;</span>),<br>(<span class="hljs-string">&#x27;109&#x27;</span>,<span class="hljs-string">&#x27;王芳&#x27;</span>,<span class="hljs-string">&#x27;女&#x27;</span>,<span class="hljs-string">&#x27;1977-09-01&#x27;</span>,<span class="hljs-string">&#x27;95031&#x27;</span>),<br>(<span class="hljs-string">&#x27;103&#x27;</span>,<span class="hljs-string">&#x27;陆君&#x27;</span>,<span class="hljs-string">&#x27;男&#x27;</span>,<span class="hljs-string">&#x27;1977-09-01&#x27;</span>,<span class="hljs-string">&#x27;95031&#x27;</span>);<br><span class="hljs-comment">-- 课程表数据的插入：</span><br><span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> course <span class="hljs-keyword">VALUES</span><br>(<span class="hljs-string">&#x27;3-105&#x27;</span>,<span class="hljs-string">&#x27;计算机导论&#x27;</span>,<span class="hljs-string">&#x27;825&#x27;</span>),<br>(<span class="hljs-string">&#x27;3-245&#x27;</span>,<span class="hljs-string">&#x27;操作系统&#x27;</span>,<span class="hljs-string">&#x27;804&#x27;</span>),<br>(<span class="hljs-string">&#x27;6-166&#x27;</span>,<span class="hljs-string">&#x27;数字电路&#x27;</span>,<span class="hljs-string">&#x27;856&#x27;</span>),<br>(<span class="hljs-string">&#x27;9-888&#x27;</span>,<span class="hljs-string">&#x27;高等数学&#x27;</span>,<span class="hljs-string">&#x27;831&#x27;</span>);<br><span class="hljs-comment">-- 成绩表数据的插入：</span><br><span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> score(sno,cno,degree) <span class="hljs-keyword">VALUES</span><br>(<span class="hljs-string">&#x27;103&#x27;</span>,<span class="hljs-string">&#x27;3-245&#x27;</span>,<span class="hljs-string">&#x27;86&#x27;</span>),<br>(<span class="hljs-string">&#x27;105&#x27;</span>,<span class="hljs-string">&#x27;3-245&#x27;</span>,<span class="hljs-string">&#x27;75&#x27;</span>),<br>(<span class="hljs-string">&#x27;109&#x27;</span>,<span class="hljs-string">&#x27;3-245&#x27;</span>,<span class="hljs-string">&#x27;68&#x27;</span>),<br>(<span class="hljs-string">&#x27;103&#x27;</span>,<span class="hljs-string">&#x27;3-105&#x27;</span>,<span class="hljs-string">&#x27;92&#x27;</span>),<br>(<span class="hljs-string">&#x27;105&#x27;</span>,<span class="hljs-string">&#x27;3-105&#x27;</span>,<span class="hljs-string">&#x27;88&#x27;</span>),<br>(<span class="hljs-string">&#x27;109&#x27;</span>,<span class="hljs-string">&#x27;3-105&#x27;</span>,<span class="hljs-string">&#x27;76&#x27;</span>),<br>(<span class="hljs-string">&#x27;101&#x27;</span>,<span class="hljs-string">&#x27;3-105&#x27;</span>,<span class="hljs-string">&#x27;64&#x27;</span>),<br>(<span class="hljs-string">&#x27;107&#x27;</span>,<span class="hljs-string">&#x27;3-105&#x27;</span>,<span class="hljs-string">&#x27;91&#x27;</span>),<br>(<span class="hljs-string">&#x27;108&#x27;</span>,<span class="hljs-string">&#x27;3-105&#x27;</span>,<span class="hljs-string">&#x27;78&#x27;</span>),<br>(<span class="hljs-string">&#x27;101&#x27;</span>,<span class="hljs-string">&#x27;6-166&#x27;</span>,<span class="hljs-string">&#x27;85&#x27;</span>),<br>(<span class="hljs-string">&#x27;107&#x27;</span>,<span class="hljs-string">&#x27;6-166&#x27;</span>,<span class="hljs-string">&#x27;79&#x27;</span>),<br>(<span class="hljs-string">&#x27;108&#x27;</span>,<span class="hljs-string">&#x27;6-166&#x27;</span>,<span class="hljs-string">&#x27;81&#x27;</span>);<br><span class="hljs-comment">-- 教师表数据的插入：</span><br><span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> teacher <span class="hljs-keyword">VALUES</span><br>(<span class="hljs-string">&#x27;804&#x27;</span>,<span class="hljs-string">&#x27;李诚&#x27;</span>,<span class="hljs-string">&#x27;男&#x27;</span>,<span class="hljs-string">&#x27;1958-12-02&#x27;</span>,<span class="hljs-string">&#x27;副教授&#x27;</span>,<span class="hljs-string">&#x27;计算机系&#x27;</span>),<br>(<span class="hljs-string">&#x27;856&#x27;</span>,<span class="hljs-string">&#x27;张旭&#x27;</span>,<span class="hljs-string">&#x27;男&#x27;</span>,<span class="hljs-string">&#x27;1969-03-12&#x27;</span>,<span class="hljs-string">&#x27;讲师&#x27;</span>,<span class="hljs-string">&#x27;电子工程系&#x27;</span>),<br>(<span class="hljs-string">&#x27;825&#x27;</span>,<span class="hljs-string">&#x27;王萍&#x27;</span>,<span class="hljs-string">&#x27;女&#x27;</span>,<span class="hljs-string">&#x27;1972-05-05&#x27;</span>,<span class="hljs-string">&#x27;助教&#x27;</span>,<span class="hljs-string">&#x27;计算机系&#x27;</span>),<br>(<span class="hljs-string">&#x27;831&#x27;</span>,<span class="hljs-string">&#x27;刘冰&#x27;</span>,<span class="hljs-string">&#x27;女&#x27;</span>,<span class="hljs-string">&#x27;1977-08-14&#x27;</span>,<span class="hljs-string">&#x27;助教&#x27;</span>,<span class="hljs-string">&#x27;电子工程系&#x27;</span>);<br><br></code></pre></td></tr></table></figure>

<h2 id="3、DQL-查询语言"><a href="#3、DQL-查询语言" class="headerlink" title="3、DQL(查询语言)"></a>3、DQL(查询语言)</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br></pre></td><td class="code"><pre><code class="hljs SQL"><span class="hljs-comment">-- ===============题目================== </span><br><span class="hljs-comment">-- 1. 查询student表中的所有记录sname，ssex，class</span><br><span class="hljs-keyword">SELECT</span> `sname`,`ssex`,`class` <span class="hljs-keyword">FROM</span> student;<br><br><span class="hljs-comment">-- 2. 查询所有教师单位不重复的depart列</span><br><br><span class="hljs-comment">-- 第一种方式</span><br><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">DISTINCT</span> `depart` <span class="hljs-keyword">FROM</span> teacher;<br><br><span class="hljs-comment">-- 第二种方式</span><br><span class="hljs-keyword">SELECT</span> `depart` <span class="hljs-keyword">FROM</span> teacher <span class="hljs-keyword">GROUP</span> <span class="hljs-keyword">BY</span> `depart`;<br><br><span class="hljs-comment">-- 3.查询student中所有记录</span><br><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> student;<br><br><span class="hljs-comment">-- 4. 查询score中成绩在60(包含)~80(不包含）的列</span><br><br><span class="hljs-comment">-- 第一种方式</span><br><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> score <span class="hljs-keyword">WHERE</span> `degree` <span class="hljs-keyword">BETWEEN</span> <span class="hljs-number">60</span> <span class="hljs-keyword">AND</span> <span class="hljs-number">80</span>;<br><br><span class="hljs-comment">-- 第二种方式</span><br><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> score <span class="hljs-keyword">WHERE</span> `degree`<span class="hljs-operator">&gt;=</span><span class="hljs-number">60</span> <span class="hljs-keyword">AND</span> `degree`<span class="hljs-operator">&lt;</span><span class="hljs-number">80</span>;<br><br><span class="hljs-comment">-- 5.查询成绩为85 86 或者88 记录</span><br><br><span class="hljs-comment">-- 第一种方式</span><br><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> score <span class="hljs-keyword">WHERE</span> `degree`<span class="hljs-operator">=</span><span class="hljs-number">85</span> <span class="hljs-keyword">OR</span> `degree`<span class="hljs-operator">=</span><span class="hljs-number">86</span> <span class="hljs-keyword">OR</span> `degree`<span class="hljs-operator">=</span><span class="hljs-number">88</span>;<br><br><span class="hljs-comment">-- 第二种方式</span><br><br><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> score <span class="hljs-keyword">WHERE</span> `degree` <span class="hljs-keyword">IN</span>(<span class="hljs-number">85</span>,<span class="hljs-number">86</span>,<span class="hljs-number">88</span>);<br><br><span class="hljs-comment">-- 6.查询student表中“95031”班或性别为“女”的同学记录。</span><br><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> student <span class="hljs-keyword">WHERE</span> class<span class="hljs-operator">=</span><span class="hljs-string">&#x27;95031&#x27;</span> <span class="hljs-keyword">OR</span> ssex<span class="hljs-operator">=</span><span class="hljs-string">&#x27;女&#x27;</span>;<br><br><span class="hljs-comment">-- 7. 以class降序查询student表的所有记录。</span><br><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> student <span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> `class` <span class="hljs-keyword">DESC</span>;<br><br><span class="hljs-comment">-- 8.以cno升序、degree降序查询Score表的所有记录。</span><br><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> score <span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> `cno` <span class="hljs-keyword">ASC</span> , `degree` <span class="hljs-keyword">DESC</span>;<br><br><span class="hljs-comment">-- 9.查询“95031”班的学生人数。</span><br><span class="hljs-keyword">SELECT</span> <span class="hljs-built_in">COUNT</span>(sno) <span class="hljs-keyword">FROM</span> student <span class="hljs-keyword">WHERE</span> class<span class="hljs-operator">=</span>&quot;95031&quot;;<br><br><span class="hljs-comment">-- 10. 查询Score表中的最高分的sno和cno。（子查询或者排序）</span><br><br><span class="hljs-comment">-- 子查询方式</span><br><span class="hljs-keyword">SELECT</span> `sno`,`cno` <span class="hljs-keyword">FROM</span> score<br><span class="hljs-keyword">WHERE</span> degree <span class="hljs-operator">=</span>(<br>  <span class="hljs-keyword">SELECT</span> <span class="hljs-built_in">MAX</span>(`degree`) <span class="hljs-keyword">FROM</span> score<br>);<br><br><span class="hljs-comment">-- 排序</span><br><span class="hljs-keyword">SELECT</span> `sno`,`cno` <span class="hljs-keyword">FROM</span> score<br><span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> degree <span class="hljs-keyword">DESC</span><br>LIMIT <span class="hljs-number">0</span>,<span class="hljs-number">1</span>;<br><br><br><span class="hljs-comment">-- 11.查询每门课的cno、总人数、平均成绩。</span><br><span class="hljs-keyword">SELECT</span> `cno`,<span class="hljs-built_in">COUNT</span>(<span class="hljs-number">1</span>) <span class="hljs-keyword">AS</span> <span class="hljs-string">&#x27;总人数&#x27;</span>,<span class="hljs-built_in">AVG</span>(`degree`) <span class="hljs-keyword">AS</span> <span class="hljs-string">&#x27;平均分&#x27;</span> <span class="hljs-keyword">FROM</span> score <span class="hljs-keyword">GROUP</span> <span class="hljs-keyword">BY</span> `cno`;<br><br><br><span class="hljs-comment">-- 12.查询Score表中至少有5名学生选修的并以3开头的课程号的cno、总人数、平均分。</span><br><span class="hljs-keyword">SELECT</span> s.`cno`,<span class="hljs-built_in">COUNT</span>(<span class="hljs-operator">*</span>) <span class="hljs-keyword">AS</span> <span class="hljs-string">&#x27;总人数&#x27;</span>,<span class="hljs-built_in">AVG</span>(`degree`) <span class="hljs-keyword">AS</span> <span class="hljs-string">&#x27;平均分&#x27;</span> <span class="hljs-keyword">FROM</span> score  <span class="hljs-keyword">AS</span> s<br><span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> course <span class="hljs-keyword">AS</span> c<br><span class="hljs-keyword">ON</span> c.`cno` <span class="hljs-operator">=</span> s.`cno`<br><span class="hljs-keyword">WHERE</span> c.`cno` <span class="hljs-keyword">LIKE</span> <span class="hljs-string">&#x27;3%&#x27;</span><br><span class="hljs-keyword">GROUP</span> <span class="hljs-keyword">BY</span> c.`cno`<br><span class="hljs-keyword">HAVING</span> <span class="hljs-built_in">COUNT</span>(<span class="hljs-operator">*</span>)<span class="hljs-operator">&gt;</span><span class="hljs-number">5</span>;<br><br><span class="hljs-comment">-- 13.查询分数大于70，小于90的sno、degree。</span><br><br><span class="hljs-keyword">SELECT</span> `sno`,`degree` <span class="hljs-keyword">FROM</span> score <span class="hljs-keyword">WHERE</span> `degree`<span class="hljs-operator">&gt;</span><span class="hljs-number">70</span> <span class="hljs-keyword">AND</span> `degree`<span class="hljs-operator">&lt;</span><span class="hljs-number">90</span>;<br><br><span class="hljs-comment">-- 14.查询所有学生的sname、cno和degree列。(多表查询)</span><br><br><span class="hljs-comment">-- 第一种方式</span><br><span class="hljs-keyword">SELECT</span> `sname`,`cno`,`degree` <span class="hljs-keyword">FROM</span> student,score<br><span class="hljs-keyword">WHERE</span> student.`sno`<span class="hljs-operator">=</span> score.`sno`;<br><br><span class="hljs-comment">-- 第二种方式：联合查询</span><br><span class="hljs-keyword">SELECT</span> `sname`,`cno`,`degree` <span class="hljs-keyword">FROM</span> student <span class="hljs-keyword">AS</span> s<br><span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> score sc<br><span class="hljs-keyword">ON</span> s.`sno`<span class="hljs-operator">=</span>sc.`sno`;<br><br><br><span class="hljs-comment">-- 15.查询所有学生的sno、cname和degree列（如果学生没有cname 和 degree 也需要查询出来)。</span><br><br><span class="hljs-keyword">SELECT</span> sc.`sno`,`cname`,`degree` <span class="hljs-keyword">FROM</span> score <span class="hljs-keyword">AS</span> sc<br><span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> course <span class="hljs-keyword">AS</span> c<br><span class="hljs-keyword">ON</span> sc.`cno`<span class="hljs-operator">=</span>c.`cno`;<br><br><span class="hljs-comment">-- 16.查询“95033”班学生的cno,平均分(子查询和多表查询)。</span><br><br><span class="hljs-comment">-- 多表查询方式一</span><br><span class="hljs-keyword">SELECT</span> `cno`,<span class="hljs-built_in">AVG</span>(`degree`) <span class="hljs-keyword">AS</span> <span class="hljs-string">&#x27;平均分&#x27;</span> <span class="hljs-keyword">FROM</span> student s<br><span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> score sc<br><span class="hljs-keyword">ON</span> s.`sno`<span class="hljs-operator">=</span>sc.`sno`<br><span class="hljs-keyword">WHERE</span> `class`<span class="hljs-operator">=</span><span class="hljs-string">&#x27;95033&#x27;</span>;<br><br><span class="hljs-comment">-- 多表查询方式二</span><br><span class="hljs-keyword">SELECT</span> cno,<span class="hljs-built_in">AVG</span>(`degree`) <span class="hljs-keyword">AS</span> <span class="hljs-string">&#x27;平均分&#x27;</span> <span class="hljs-keyword">FROM</span> score,student<br><span class="hljs-keyword">WHERE</span> score.`sno`<span class="hljs-operator">=</span>student.`sno` <span class="hljs-keyword">AND</span> student.`class`<span class="hljs-operator">=</span><span class="hljs-string">&#x27;95033&#x27;</span>;<br><br><span class="hljs-comment">-- 子查询</span><br><span class="hljs-keyword">SELECT</span> cno,<span class="hljs-built_in">AVG</span>(`degree`) <span class="hljs-keyword">AS</span> <span class="hljs-string">&#x27;平均分&#x27;</span> <span class="hljs-keyword">FROM</span> score <br><span class="hljs-keyword">WHERE</span> sno <span class="hljs-keyword">IN</span>(<br>  <span class="hljs-keyword">SELECT</span> `sno` <span class="hljs-keyword">FROM</span> student <span class="hljs-keyword">WHERE</span> `class`<span class="hljs-operator">=</span><span class="hljs-string">&#x27;95033&#x27;</span><br>);<br><br><br><span class="hljs-comment">-- 17.查询课程号为“3-105”课程且学号为“109”号同学成绩的记录（子查询和多边查询）。</span><br><br><span class="hljs-comment">-- 子查询</span><br><br><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> student <br><span class="hljs-keyword">WHERE</span> sno <span class="hljs-keyword">IN</span>(<br>  <span class="hljs-keyword">SELECT</span> `sno` <span class="hljs-keyword">FROM</span> score <span class="hljs-keyword">WHERE</span> `cno`<span class="hljs-operator">=</span><span class="hljs-string">&#x27;3-105&#x27;</span> <span class="hljs-keyword">AND</span> `sno`<span class="hljs-operator">=</span><span class="hljs-number">109</span><br>);<br><br><span class="hljs-comment">-- 多表查询</span><br><br><span class="hljs-comment">-- 方式一</span><br><span class="hljs-keyword">SELECT</span> s.<span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> student <span class="hljs-keyword">AS</span> s <br><span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> score <span class="hljs-keyword">AS</span> sc<br><span class="hljs-keyword">ON</span> s.`sno`<span class="hljs-operator">=</span>sc.`sno`<br><span class="hljs-keyword">WHERE</span> `cno`<span class="hljs-operator">=</span><span class="hljs-string">&#x27;3-105&#x27;</span> <span class="hljs-keyword">AND</span> sc.`sno`<span class="hljs-operator">=</span><span class="hljs-number">109</span>;<br><br><span class="hljs-comment">-- 方式二</span><br><span class="hljs-keyword">SELECT</span> s.<span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> student <span class="hljs-keyword">AS</span> s,score <span class="hljs-keyword">AS</span> sc <span class="hljs-keyword">WHERE</span> s.`sno`<span class="hljs-operator">=</span>sc.`sno`  <span class="hljs-keyword">AND</span> `cno`<span class="hljs-operator">=</span><span class="hljs-string">&#x27;3-105&#x27;</span> <span class="hljs-keyword">AND</span> sc.`sno`<span class="hljs-operator">=</span><span class="hljs-number">109</span>;<br><br><br><span class="hljs-comment">-- 18.查询score中选学2门课程的同学的sno、总成绩(且按照总成绩降序排序)。</span><br><span class="hljs-keyword">SELECT</span> `sno`,<span class="hljs-built_in">SUM</span>(`degree`) <span class="hljs-keyword">AS</span> <span class="hljs-string">&#x27;总成绩&#x27;</span> <span class="hljs-keyword">FROM</span> score <br><span class="hljs-keyword">GROUP</span> <span class="hljs-keyword">BY</span> `sno`<br><span class="hljs-keyword">HAVING</span> <span class="hljs-built_in">COUNT</span>(`sno`)<span class="hljs-operator">=</span><span class="hljs-number">2</span> <br><span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> <span class="hljs-built_in">SUM</span>(`degree`) <span class="hljs-keyword">DESC</span><br><br><span class="hljs-comment">-- 19.查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录。</span><br><br><span class="hljs-comment">-- 子查询</span><br><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> score <span class="hljs-keyword">WHERE</span> `degree`<span class="hljs-operator">&gt;</span>(<br> <span class="hljs-keyword">SELECT</span> `degree` <span class="hljs-keyword">FROM</span> score <span class="hljs-keyword">WHERE</span>  `sno`<span class="hljs-operator">=</span><span class="hljs-string">&#x27;109&#x27;</span> <span class="hljs-keyword">AND</span> `cno`<span class="hljs-operator">=</span><span class="hljs-string">&#x27;3-105&#x27;</span><br>);<br><br><br><span class="hljs-comment">-- 20.查询和学号为108的同学同年出生的所有学生的sno、sname和sbirthday列。</span><br><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> student <span class="hljs-keyword">WHERE</span> `sbirthday` <span class="hljs-keyword">IN</span>(<br>  <span class="hljs-keyword">SELECT</span> `sbirthday` <span class="hljs-keyword">FROM</span> student <span class="hljs-keyword">WHERE</span> sno <span class="hljs-operator">=</span> <span class="hljs-string">&#x27;108&#x27;</span><br>);<br><br><br><span class="hljs-comment">-- 21. 获取“张旭&quot;教师所交课程课程号以及课程名</span><br><br><span class="hljs-keyword">SELECT</span> `cno`,`cname` <span class="hljs-keyword">FROM</span> course <span class="hljs-keyword">AS</span> c<br><span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> teacher <span class="hljs-keyword">AS</span>  t<br><span class="hljs-keyword">ON</span> t.`tno`<span class="hljs-operator">=</span>c.`tno`<br><span class="hljs-keyword">WHERE</span> t.`tname`<span class="hljs-operator">=</span>&quot;张旭&quot;;<br><br><br><span class="hljs-comment">-- 21.查询“张旭“教师任课的学生成绩（姓名）。</span><br><br><span class="hljs-comment">-- 方式一</span><br><span class="hljs-keyword">SELECT</span> `sname`,`degree` <span class="hljs-keyword">FROM</span> student<br><span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> score<br><span class="hljs-keyword">ON</span> student.`sno`<span class="hljs-operator">=</span>score.`sno`<br><span class="hljs-keyword">WHERE</span> score.sno <span class="hljs-keyword">IN</span>(<br>  <span class="hljs-keyword">SELECT</span> s.`sno` <span class="hljs-keyword">FROM</span> course <span class="hljs-keyword">AS</span> c <br>  <span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> teacher <span class="hljs-keyword">AS</span> t<br>  <span class="hljs-keyword">ON</span> c.`tno`<span class="hljs-operator">=</span>t.`tno`<br>  <span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> score <span class="hljs-keyword">AS</span> sc<br>  <span class="hljs-keyword">ON</span> sc.`cno`<span class="hljs-operator">=</span>c.`cno`<br>  <span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> student  <span class="hljs-keyword">AS</span> s<br>  <span class="hljs-keyword">ON</span> s.`sno`<span class="hljs-operator">=</span>sc.`sno`<br>  <span class="hljs-keyword">WHERE</span> t.`tname`<span class="hljs-operator">=</span>&quot;张旭&quot;<br>);<br><br><span class="hljs-comment">-- 方式二</span><br><span class="hljs-keyword">SELECT</span> `sname`,`degree` <span class="hljs-keyword">FROM</span> student<br><span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> score<br><span class="hljs-keyword">ON</span> student.`sno`<span class="hljs-operator">=</span>score.`sno`<br><span class="hljs-keyword">WHERE</span> score.sno <span class="hljs-keyword">IN</span>(<br>  <span class="hljs-keyword">SELECT</span> s.sno <span class="hljs-keyword">FROM</span> student <span class="hljs-keyword">AS</span> s,score <span class="hljs-keyword">AS</span> sc<br>  <span class="hljs-keyword">WHERE</span> sc.`sno`<span class="hljs-operator">=</span>s.`sno` <span class="hljs-keyword">AND</span> cno <span class="hljs-keyword">IN</span>(<span class="hljs-keyword">SELECT</span> cno <span class="hljs-keyword">FROM</span> course <span class="hljs-keyword">AS</span> c,teacher <span class="hljs-keyword">AS</span> t <span class="hljs-keyword">WHERE</span> c.`tno`<span class="hljs-operator">=</span>t.`tno` <span class="hljs-keyword">AND</span> t.`tname`<span class="hljs-operator">=</span>&quot;张旭&quot;)<br>);<br><br><br><span class="hljs-comment">-- 22 查询考计算机导论的学生成绩（子查询)</span><br><span class="hljs-keyword">SELECT</span> `degree` <span class="hljs-keyword">FROM</span> score <span class="hljs-keyword">WHERE</span> `cno` <span class="hljs-keyword">IN</span>(<br>  <span class="hljs-keyword">SELECT</span> `cno` <span class="hljs-keyword">FROM</span> course <span class="hljs-keyword">WHERE</span> cname<span class="hljs-operator">=</span>&quot;计算机导论&quot;<br>);<br><br><span class="hljs-comment">-- 23.教高等数学的老师是叫什么，哪个系的(子查询)</span><br><span class="hljs-keyword">SELECT</span> `tname`,`depart` <span class="hljs-keyword">FROM</span> teacher <span class="hljs-keyword">WHERE</span> `tno` <span class="hljs-keyword">IN</span>(<br>    <span class="hljs-keyword">SELECT</span> `tno` <span class="hljs-keyword">FROM</span> course <span class="hljs-keyword">WHERE</span> `cname`<span class="hljs-operator">=</span>&quot;高等数学&quot;<br>);<br><br><br><span class="hljs-comment">-- 24.查询所有教师和同学的name、sex和birthday.(联合查询)</span><br><span class="hljs-keyword">SELECT</span> t.`tname` <span class="hljs-keyword">AS</span> <span class="hljs-string">&#x27;name&#x27;</span>,t.`tsex` <span class="hljs-keyword">AS</span> <span class="hljs-string">&#x27;sex&#x27;</span>,t.`tbirthday` <span class="hljs-keyword">AS</span> <span class="hljs-string">&#x27;birthday&#x27;</span> <span class="hljs-keyword">FROM</span> teacher <span class="hljs-keyword">AS</span> t<br><span class="hljs-keyword">UNION</span><br><span class="hljs-keyword">SELECT</span> s.`sname`,s.`ssex`,s.`sbirthday`  <span class="hljs-keyword">FROM</span> student <span class="hljs-keyword">AS</span> s;<br><br><br><span class="hljs-comment">-- 25.查询选修某课程的同学人数多于5人的教师姓名(子查询)。</span><br><span class="hljs-keyword">SELECT</span> `tname` <span class="hljs-keyword">FROM</span> teacher <span class="hljs-keyword">WHERE</span> tno <span class="hljs-keyword">IN</span>(<br>  <span class="hljs-keyword">SELECT</span> `tno` <span class="hljs-keyword">FROM</span> course <span class="hljs-keyword">WHERE</span> `cno` <span class="hljs-keyword">IN</span>(<br>    <span class="hljs-keyword">SELECT</span> `cno` <span class="hljs-keyword">FROM</span> score <span class="hljs-keyword">GROUP</span> <span class="hljs-keyword">BY</span> `cno` <span class="hljs-keyword">HAVING</span> <span class="hljs-built_in">COUNT</span>(`sno`)<span class="hljs-operator">&gt;=</span><span class="hljs-number">5</span><br>  )<br>);<br><br><br><span class="hljs-comment">-- 26查询最高分同学的Sno、Cno和Degree列(子查询）。</span><br><br> <span class="hljs-keyword">SELECT</span> `sno`,`cno`,`degree` <span class="hljs-keyword">FROM</span>  score <span class="hljs-keyword">WHERE</span> `degree`<span class="hljs-operator">=</span>(<br>  <span class="hljs-keyword">SELECT</span> <span class="hljs-built_in">MAX</span>(`degree`) <span class="hljs-keyword">FROM</span> score<br> );<br> <br> <br> <span class="hljs-comment">-- 27.查询Student表中不姓“王”的同学记录。</span><br> <span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> student <span class="hljs-keyword">WHERE</span> sno <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">IN</span>(<br>  <span class="hljs-keyword">SELECT</span> sno <span class="hljs-keyword">FROM</span> student <span class="hljs-keyword">WHERE</span> `sname` <span class="hljs-keyword">LIKE</span> <span class="hljs-string">&#x27;王%&#x27;</span><br> );<br> <br> <br> <span class="hljs-comment">-- 28.查询Student表中每个学生的姓名和年龄。</span><br><span class="hljs-keyword">SELECT</span> `sname`,  <span class="hljs-built_in">FLOOR</span>(DATEDIFF(CURDATE(),`sbirthday`)<span class="hljs-operator">/</span><span class="hljs-number">365.2422</span>) <span class="hljs-keyword">AS</span> <span class="hljs-string">&#x27;年龄&#x27;</span> <span class="hljs-keyword">FROM</span> student; <br> <br><br> <br><span class="hljs-comment">-- 29.查询所有任课教师的Tname和Depart.</span><br><span class="hljs-keyword">SELECT</span> `tname`,`depart` <span class="hljs-keyword">FROM</span> teacher;<br><br><br><span class="hljs-comment">-- 30.查询所有成绩比3-105课程平均成绩低的同学的成绩表。</span><br><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> score <span class="hljs-keyword">WHERE</span> `degree`<span class="hljs-operator">&lt;</span>(<br>  <span class="hljs-keyword">SELECT</span> <span class="hljs-built_in">AVG</span>(`degree`) <span class="hljs-keyword">FROM</span> score <span class="hljs-keyword">WHERE</span> cno<span class="hljs-operator">=</span>&quot;3-105&quot;<br>);<br></code></pre></td></tr></table></figure>
              
            </div>
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E5%BC%80%E5%8F%91/" class="category-chain-item">开发</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/%E6%95%B0%E6%8D%AE%E5%BA%93/">#数据库</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>SQL语句练习</div>
      <div>http://example.com/2022/06/05/SQL基础语句日常练习/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Wahoyu</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年6月5日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/06/08/Java%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E7%AE%80%E5%8D%95%E5%AE%9E%E7%8E%B0/" title="数据结构实现（Java）">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">数据结构实现（Java）</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/06/03/%E8%A7%A3%E5%86%B3Linux%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E6%AF%8F%E6%AC%A1%E8%A6%81source-etc-profile%E9%97%AE%E9%A2%98/" title="解决Linux环境变量每次要source /etc/profile问题">
                        <span class="hidden-mobile">解决Linux环境变量每次要source /etc/profile问题</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  <article id="comments" lazyload>
    
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.4.16/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"7WuaJQGQGU5GFxMKMtDzWYVI-gzGzoHsz","appKey":"zdCzx5CuURztPQQoi8LuXSWv","path":"window.location.pathname","placeholder":"请留下您的想法...","avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":false,"recordIP":true,"serverURLs":"https://7wuajqgq.lc-cn-n1-shared.com","emojiCDN":null,"emojiMaps":null,"enableQQ":true},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


  </article>


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  






    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <text>哆啦是个梦</text> <div style="font-size: 0.85rem"> <span id="timeDate">载入天数...</span> <span id="times">载入时分秒...</span> <script src="/js/duration.js"></script> </div> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  

  

  

  

  

  

  




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.0/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script>
  (function() {
    var enableLang = CONFIG.code_language.enable && CONFIG.code_language.default;
    var enableCopy = CONFIG.copy_btn;
    if (!enableLang && !enableCopy) {
      return;
    }

    function getBgClass(ele) {
      return Fluid.utils.getBackgroundLightness(ele) >= 0 ? 'code-widget-light' : 'code-widget-dark';
    }

    var copyTmpl = '';
    copyTmpl += '<div class="code-widget">';
    copyTmpl += 'LANG';
    copyTmpl += '</div>';
    jQuery('.markdown-body pre').each(function() {
      var $pre = jQuery(this);
      if ($pre.find('code.mermaid').length > 0) {
        return;
      }
      if ($pre.find('span.line').length > 0) {
        return;
      }

      var lang = '';

      if (enableLang) {
        lang = CONFIG.code_language.default;
        if ($pre[0].children.length > 0 && $pre[0].children[0].classList.length >= 2 && $pre.children().hasClass('hljs')) {
          lang = $pre[0].children[0].classList[1];
        } else if ($pre[0].getAttribute('data-language')) {
          lang = $pre[0].getAttribute('data-language');
        } else if ($pre.parent().hasClass('sourceCode') && $pre[0].children.length > 0 && $pre[0].children[0].classList.length >= 2) {
          lang = $pre[0].children[0].classList[1];
          $pre.parent().addClass('code-wrapper');
        } else if ($pre.parent().hasClass('markdown-body') && $pre[0].classList.length === 0) {
          $pre.wrap('<div class="code-wrapper"></div>');
        }
        lang = lang.toUpperCase().replace('NONE', CONFIG.code_language.default);
      }
      $pre.append(copyTmpl.replace('LANG', lang).replace('code-widget">',
        getBgClass($pre[0]) + (enableCopy ? ' code-widget copy-btn" data-clipboard-snippet><i class="iconfont icon-copy"></i>' : ' code-widget">')));

      if (enableCopy) {
        Fluid.utils.createScript('https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js', function() {
          var clipboard = new window.ClipboardJS('.copy-btn', {
            target: function(trigger) {
              var nodes = trigger.parentNode.childNodes;
              for (var i = 0; i < nodes.length; i++) {
                if (nodes[i].tagName === 'CODE') {
                  return nodes[i];
                }
              }
            }
          });
          clipboard.on('success', function(e) {
            e.clearSelection();
            e.trigger.innerHTML = e.trigger.innerHTML.replace('icon-copy', 'icon-success');
            setTimeout(function() {
              e.trigger.innerHTML = e.trigger.innerHTML.replace('icon-success', 'icon-copy');
            }, 2000);
          });
        });
      }
    });
  })();
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>




  
<script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/xiantiao.js"></script>



<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
